import json
import random
import time

import requests


def queryShunfeng(number):
    m = {"id": "shunfeng", "order": number, "s": "cd8fad6c1e57eec9fba656a926815d38"}

    result = requests.post('https://www.aikuaidi.cn/query', data=m).content
    r = json.loads(result)
    r = json.dumps(r, indent=" ")
    print(r)
    pass


for i in range(1):
    # number = "940001731394"
    print("request count = %s" % i)

    number = "439556070330"
    resp = requests.post("https://www.kuaidi100.com/autonumber/autoComNum?resultv2=1&text=%s" % number)
    resp_content = resp.content

    params = json.loads(resp_content)
    company_name = params["auto"][0]["comCode"]

    if company_name == 'shunfeng':
        queryShunfeng(number)
        continue

    u = "https://www.kuaidi100.com/query?type=%s&postid=%s&temp=%s" % (company_name, number, random.random())
    result = requests.get(u).content
    r = json.loads(result)
    r = json.dumps(r, indent=" ")
    print(r)
    time.sleep(random.random())
